#include <bits/stdc++.h>
using namespace std;
int h[101][101];
int di[] = {-1, 1, 0, 0};
int dj[] = {0, 0, 1, -1};
int ans = INT_MIN;
int R, C;
int help[101][101];

int search(int i, int j) {
  if (help[i][j] != 0)
    return help[i][j];
  int da = 0;
  for (int k = 0; k < 4; k++) {
    int newi = i + di[k];
    int newj = j + dj[k];
    if (newi >= 1 && newi <= R && newj >= 1 && newj <= C &&
        h[newi][newj] < h[i][j]) {
      int len = search(newi, newj);
      da = max(da, len);
    }
  }
  return help[i][j] = da + 1;
}
int main() {
  cin >> R >> C;
  for (int i = 1; i <= R; i++) {
    for (int j = 1; j <= C; j++) {
      cin >> h[i][j];
    }
  }
  for (int i = 1; i <= R; i++) {
    for (int j = 1; j <= C; j++) {
      int k = search(i, j);
      ans = max(ans, k);
    }
  }
  cout << ans;
  return 0;
}